package jim.h.commons;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.SerializationConfig;

public class PrettyJson {

    public static void main(String[] args) throws JsonGenerationException, JsonMappingException, IOException {
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(SerializationConfig.Feature.INDENT_OUTPUT, true);
        List<Object> list = new ArrayList<Object>();
        List<Object> list1 = new ArrayList<Object>();
        list.add("你好");
        list.add("你好@");
        list1.add("haha");
        list1.add("ddd");
        list1.add("aaa");
        list1.add("ccc");
        list.add(list1);
        String jsonString = mapper.writeValueAsString(list);
        System.out.println(jsonString);

        ObjectMapper mapper2 = new ObjectMapper();
        System.out.println(mapper2.writeValueAsString(mapper2.readValue(jsonString, List.class)));
    }
}
